package com.hello.booksale.dao;

import com.hello.booksale.entity.BookEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BookDao {
    @Select("SELECT * FROM book")
    List<BookEntity> findAllBooks();

    @Select("SELECT * FROM book WHERE book_id=#{bookId}")
    BookEntity findBooksById(@Param("bookId") int bookId);

    @Select("SELECT * FROM book WHERE book_name LIKE CONCAT('%',#{bookName},'%')")
    List<BookEntity> findBookByBookName(@Param("bookName") String bookName);

    @Select("SELECT * FROM book LIMIT #{pageBegin}, #{pageSize}")
    List<BookEntity> findBooksByPage(@Param("pageBegin") int pageBegin, @Param("pageSize") int pageSize);

    @Select("SELECT COUNT(book_id) FROM book")
    int selectCount();

    @Delete("DELETE FROM book WHERE book_id=#{bookId}")
    void deleteBookById(@Param("bookId") int bookId);

    @Insert("INSERT INTO book(book_name,book_author,book_price,book_detail,book_sales,book_stock,book_url) VALUES(#{bookName},#{bookAuthor},#{bookPrice},#{bookDetail},#{bookSales},#{bookStock},#{bookUrl})")
    void addBook(BookEntity bookEntity);

    @Update("UPDATE book SET book_name=#{bookName},book_author=#{bookAuthor},book_price=#{bookPrice},book_detail=#{bookDetail},book_sales=#{bookSales},book_stock=#{bookStock},book_url=#{bookUrl} WHERE book_id=#{bookId}")
    void updateBook(BookEntity bookEntity);


}
